<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>客户列表-BootCRM</title>

<!-- Bootstrap Core CSS -->
<link href="<%=basePath%>static/css/bootstrap.min.css" rel="stylesheet">

<!-- MetisMenu CSS -->
<link href="<%=basePath%>static/css/metisMenu.min.css" rel="stylesheet">

<!-- DataTables CSS -->
<link href="<%=basePath%>static/css/dataTables.bootstrap.css" rel="stylesheet">

<!-- Custom CSS -->
<link href="<%=basePath%>static/css/sb-admin-2.css" rel="stylesheet">

<!-- Custom Fonts -->
<link href="<%=basePath%>static/css/font-awesome.min.css" rel="stylesheet"
	type="text/css">
<link href="<%=basePath%>static/css/boot-crm.css" rel="stylesheet"
	type="text/css">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

	<div id="wrapper">
		<%--<!-- Navigation -->
		<nav class="navbar navbar-default navbar-static-top" role="navigation"
			style="margin-bottom: 0">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target=".navbar-collapse">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand" href="#">BOOT客户管理系统 v2.0</a>
		</div>
		<!-- /.navbar-header --> <!-- /.navbar-top-links -->
		<div class="navbar-default sidebar" role="navigation">
			<div class="sidebar-nav navbar-collapse">
				<ul class="nav" id="side-menu">
					<li class="sidebar-search">
						<div class="input-group custom-search-form">
							<input type="text" class="form-control" placeholder="查询内容...">
							<span class="input-group-btn">
								<button class="btn btn-default" type="button">
									<i class="fa fa-search" style="padding: 3px 0 3px 0;"></i>
								</button> </span>
						</div> <!-- /input-group -->
					</li>
					<li><a href="<%=basePath%>customer/index" class="active"><i class="fa fa-edit fa-fw"></i> 客户管理</a></li>
					<li><a href="#"><i class="fa fa-dashboard fa-fw"></i> 客户拜访</a>
					</li>
				</ul>
			</div>
			<!-- /.sidebar-collapse -->
		</div>
		<!-- /.navbar-static-side --> </nav>--%>

		<!-- 高级查询 -->
		<div id="page-wrapper">
			<div class="row">
				<div class="col-lg-12">
					<h1 class="page-header">客户管理</h1>
				</div>
				<!-- /.col-lg-12 -->
			</div>
			<!-- /.row -->
			<div class="panel panel-default">
				<div class="panel-body">
					<form class="form-inline"
						action="${pageContext.request.contextPath }/customer/query"
						method="post">
						<div class="form-group">
							<label for="customerName">客户名称</label> <input type="text"
								class="form-control" id="customerName" value="${query.name }"
								name="name">
						</div>
						<div class="form-group">
							<label for="customerFrom">客户来源</label> <select
								class="form-control" id="customerFrom" placeholder="客户来源"
								name="source">
								<option value="">--请选择--</option>
								<c:forEach items="${source}" var="item">
									<option value="${item.uid}"
										<c:if test="${item.uid == query.source}"> selected</c:if>>${item.itemname
										}</option>
								</c:forEach>
							</select>
						</div>
						<div class="form-group">
							<label for="custIndustry">所属行业</label> <select
								class="form-control" id="custIndustry" name="industry">
								<option value="">--请选择--</option>
								<c:forEach items="${industry}" var="item">
									<option value="${item.uid}"
										<c:if test="${item.uid == query.industry}"> selected</c:if>>${item.itemname
										}</option>
								</c:forEach>
							</select>
						</div>
						<div class="form-group">
							<label for="custLevel">客户级别</label> <select class="form-control"
								id="custLevel" name="level">
								<option value="">--请选择--</option>
								<c:forEach items="${level}" var="item">
									<option value="${item.uid}"
										<c:if test="${item.uid == query.level}"> selected</c:if>>${item.itemname}</option>
								</c:forEach>
							</select>
						</div>
						<button type="submit" class="btn btn-primary">查询</button>
						<button type="button" class="btn btn-warning" onclick="queryClear()">重置</button>
					</form>
				</div>
			</div>

			<a href="#" class="btn btn-primary"
			   data-toggle="modal" data-target="#customerAddDialog"
			   onclick="addCustomer()">添加客户</a>
			<!-- 显示客户列表页面 -->
			<%@include file="allCustomer.jsp"%>
			
			<!-- 添加客户页面 -->
			<%@include file="addCustomer.jsp"%>
			
			<!-- 编辑客户页面 -->
			<%@include file="editCustomer.jsp"%>
			
		</div>
	</div>


	<!-- jQuery -->
	<script src="<%=basePath%>static/js/jquery.min.js"></script>
	<!-- Bootstrap Core JavaScript -->
	<script src="<%=basePath%>static/js/bootstrap.min.js"></script>
	<!-- Metis Menu Plugin JavaScript -->
	<script src="<%=basePath%>static/js/metisMenu.min.js"></script>
	<!-- DataTables JavaScript -->
	<script src="<%=basePath%>static/js/jquery.dataTables.min.js"></script>
	<script src="<%=basePath%>static/js/dataTables.bootstrap.min.js"></script>
	<!-- Custom Theme JavaScript -->
	<script src="<%=basePath%>static/js/sb-admin-2.js"></script>
	<script type="text/javascript">

		//清空高级查询框
		function queryClear() {
            $("#customerName").val("");
		    $("#custIndustry").val("");
            $("#custLevel").val("");;
            $("#customerFrom").val("");
        }
		
		//提交
		function addSubmit(){
			$.ajax({
				type:"post",
				url:"<%=basePath%>customer/update",
				data:$("#addCustomerForm").serialize(),
				success:function(data) {
					if(data){
						alert("客户信息添加成功！");
						window.location.reload();
					}else{
						alert("客户信息添加失败！请检查！");
					}
				}
			});
		}
		
		function editCustomer(id) {
			$.ajax({
				type:"post",
				url:"<%=basePath%>customer/detail",
				data:{"id":id},
				success:function(data) {
					$("#edit_cust_id").val(data.id);
					$("#edit_customerName").val(data.name);
					$("#edit_customerFrom").val(data.source)
					$("#edit_custIndustry").val(data.industry)
					$("#edit_custLevel").val(data.level)
					$("#edit_linkMan").val(data.linkman);
					$("#edit_phone").val(data.phone);
					$("#edit_mobile").val(data.mobile);
					$("#edit_zipcode").val(data.zipcode);
					$("#edit_address").val(data.address);
					
				}
			});
		}
		function updateCustomer() {
            $.ajax({
                type:"post",
                url:"<%=basePath%>customer/update",
                data:$("#edit_customer_form").serialize(),
                success:function(data) {
                    if(data){
                        alert("客户信息更新成功！");
                        window.location.reload();
					}else{
                        alert("客户信息更新失败！请检查！");
					}
                }
            });
		}
		
		function deleteCustomer(id) {
            if(confirm('确实要删除该客户吗?')) {
				$.ajax({
					type:"post",
					url:"<%=basePath%>customer/delete",
					data:{"id":id},
					success:function(data) {
                        if(data){
                            alert("客户信息删除成功！");
                            window.location.reload();
                        }else{
                            alert("客户信息删除失败！请检查！");
                        }
					}
				});
			}
		}
	</script>
</body>
</html>
